/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package principal.banco;

import extras.tela_erro;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Diego
 */
public class bd
{

    static Connection con;

    public static void Conectar()
    {

        String driver = "org.postgresql.Driver";
        String user = "postgres";
        String senha = "ER7xnmki";
        String url = "jdbc:postgresql://localhost:5432/sgh";

        try
        {
            Class.forName(driver);
            con = (Connection) DriverManager.getConnection(url, user, senha);

            // System.out.println("Conexão realizada com sucesso.");

        } catch (Exception ex)
        {
            new tela_erro(ex.getLocalizedMessage());
        }
    }

    public static ResultSet queryResult(String sql) throws SQLException
    {
        java.sql.Statement t = con.createStatement();
        return t.executeQuery(sql);
    }

    public static boolean query(String sql) throws SQLException
    {
        java.sql.Statement t = con.createStatement();
        return t.execute(sql);

    }

    public static Connection getConnection()
    {
        return con;
    }

    public static void closeConnection()
    {
        try
        {
            con.close();
        } catch (SQLException ex)
        {
            ex.printStackTrace();
        }
    }
}
